
#ifndef TARGETSET_H
#define TARGETSET_H

#include <BShape>
#include <BScene>
#include <BPickItem>

using namespace BWE;

class Target : public BObject
{
public:
	Target(BScene* scene);
	Target(BObject* object, BScene* scene);
	Target(BGroup* group, BScene* scene);
	Target(BNode* node, BScene* scene);
	Target(BShape* shape, BScene* scene);
	Target(const Target& other);
	~Target();

	bool empty() const;
	const BSpace& space() const;

	BScene* scene();
	const BScene* scene() const;

	void insertGroup(BGroup* group);
	void removeGroup(BGroup* group);
	bool containGroup(BGroup* group) const;
	void clearGroups();

	int groupCount() const;
	BGroup* group(int index) const;
	const BGroupHolderArray& groups() const;

	void insertNode(BNode* node);
	void removeNode(BNode* node);
	bool containNode(BNode* node) const;
	void clearNodes();

	int nodeCount() const;
	BNode* node(int index) const;
	const BNodeHolderArray& nodes() const;

	void insertShape(BShape* shape);
	void removeShape(BShape* shape);
	bool containShape(BShape* shape) const;
	void clearShapes();

	int shapeCount() const;
	BShape* shape(int index) const;
	const BShapeHolderArray& shapes() const;

	void insertConstraint(BConstraint* constraint);
	void removeConstraint(BConstraint* constraint);
	bool containConstraint(BConstraint* constraint) const;
	void clearConstraints();

	int constraintCount() const;
	BConstraint* constraint(int index) const;
	const BConstraintHolderArray& constraints() const;

	BNode* findNode(BNode* node) const;
	bool contain(BObject* object) const;
	bool matchPickItem(BPickItem* item);

	void clear();

	BObject* object() const;
	BShape* shape() const;
	BNode* node() const;
	BGroup* group() const;

	bool operator == (const BNode* node) const;
	bool operator == (const BShape* shape) const;

protected:
	void slotShapeDirty(BShape* shape);
	void slotShapeTransformed(BShape* shape);

	void slotNodeDirty(BNode* node);
	void slotNodeTransformed(BNode* node);

	void slotGroupDirty(BGroup* group);

private:
	mutable bool				_dirty;
	mutable BSpace				_space;
	BSceneHolder				_scene;
	BArray<BGroupHolder>		_groups;
	BArray<BNodeHolder>			_nodes;
	BArray<BShapeHolder>		_shapes;
	BArray<BConstraintHolder>	_constraints;
};

typedef BHolder<Target>		TargetHolder;

#endif